﻿using System;
using Airborne.ScrumPoker.Module.Events;
using Airborne.ScrumPoker.Module.Host.Model;

namespace Airborne.ScrumPoker.Module.Host.Tests.Mocks
{
    internal class MockScrumPokerServerConnection : IScrumPokerClientConnection
    {
        #region Properties
        public bool TimerStarted { get; private set; }
        public bool TimerStoped { get; private set; }
        public int TimerDuration { get; private set; }
        public string ClientName { get; set; }
        public bool WorkItemSelected { get; set; }
        public string WorkItemTitle { get; set; }

        #endregion

        #region IScrumPokerServer Members

        public bool Subscribe(string clientName)
        {
            return true;
        }

        public void Unsubscribe()
        {
            throw new NotImplementedException();
        }

        public void Vote(double cardValue)
        {
            RaiseVote(cardValue);
        }

        public void StartTimer(int seconds)
        {
            TimerStarted = true;
            TimerDuration = seconds;
        }

        public void StopTimer()
        {
            TimerStoped = true;
        }

        public void SelectWorkItem(string title, string description)
        {
            WorkItemSelected = true;
            WorkItemTitle = title;
        }

        public void ResetVote()
        {
        }

        public void EndGame()
        {

        }
        #endregion

        #region Vote

        public event EventHandler<GenericEventArgs<double>> Voted;

        private void RaiseVote(double vote)
        {
            GenericEventArgs<double> args = new GenericEventArgs<double>(vote);
            OnVote(args);
        }

        protected virtual void OnVote(GenericEventArgs<double> args)
        {
            EventHandler<GenericEventArgs<double>> handler = this.Voted;
            if (handler != null)
            {
                handler(this, args);
            }
        }

        #endregion

    }

}
